package com.emagic.manage.modules.main.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.emagic.manage.R;
import com.emagic.manage.data.entities.response.RoomsResponse;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by xiatian on 2017/11/1.
 */

public class RoomsAdapter extends BaseQuickAdapter<RoomsResponse.RoomsEntity, BaseViewHolder> {
    public RoomsAdapter(List<RoomsResponse.RoomsEntity> data) {
        super(R.layout.view_rooms_list_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RoomsResponse.RoomsEntity item) {

        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String startTime = null, endTime = null;
        try {
            startTime = sdf1.format(sdf2.parse(item.getStartTime()));
            endTime = sdf1.format(sdf2.parse(item.getEndTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        helper.setText(R.id.room_name, item.getRoomname())
                .setText(R.id.room_num, item.getSerial())
                .setText(R.id.time_text, startTime);
    }
}
